<template>
  <el-popover placement = "bottom-start" :width = "630" trigger = "click">
    <template #reference>
      <el-button style = "margin-right: 16px">Click to activate</el-button>
    </template>
    <el-scrollbar style = "height: 300px;">
      <el-row>
        <el-col :span = "24">
          <el-row v-for = "category1Item in props.navList" :key = "category1Item">
            <ul class = "category-container">
              <!--一级标题-->
              <div class = "category1Name">
                <span>{{ category1Item.category1Name }}</span>
              </div>
              <!--二级标题-->
              <div class = "category2Name">
                <li :key = "category2Item.category2Id"
                    v-for = "category2Item in category1Item.category1List">
                  <el-link
                      @click = "itemSelected(category2Item)"
                      :class = "{'holding':true,'selected':category2Item.isSelected} "
                      :underline = "false">
                    {{
                      category2Item.category2Name
                    }}
                  </el-link>
                </li>
              </div>

            </ul>
          </el-row>
        </el-col>
      </el-row>
    </el-scrollbar>

  </el-popover>

</template>

<script setup>
import {reactive} from "vue";

const props = defineProps({
  navList: Array
})
const activeArr = reactive([
  {
    category1Id: 1,
    category2Id: 1,
    name: '华语'
  }, {
    category1Id: 1,
    category2Id: 2,
    name: '华语'
  },

])
console.log(activeArr)

function itemSelected(category2Item) {
  // 如果 已经被选中了。就把状态切换，去activeArr中删除那个tag
  category2Item.isSelected = !category2Item.isSelected
  console.log(category2Item)
}
</script>

<style lang = "less" scoped>
.category-container {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  margin: 10px 0;

  .category1Name {
    display: flex;
    flex-wrap: nowrap;
    padding: 10px 50px 10px 0;

    span {
      margin-right: 5px;
      color: rgba(152, 150, 150, 0.6);
    }
  }

  .category2Name {
    width: 80%;
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;

    > li {
      padding: 0 40px 22px 0;
    }
  }

  .el-link {
    padding: 3px 5px;
  }
}

</style>